package test07;

import java.util.*; /**
 * 版权检测处理器
 */
public class CopyrightHandler extends ContentHandler {
    private Map<String, String> ipDatabase; // IP名称 -> 版权信息
    private String watermarkTemplate = "AIGC Generated - Copyright Protected";
    private Set<String> commercialIPs;

    public CopyrightHandler() {
        super("版权检测器");
        initializeIPDatabase();
    }

    private void initializeIPDatabase() {
        ipDatabase = new HashMap<>();
        ipDatabase.put("米老鼠", "迪士尼版权所有");
        ipDatabase.put("超级马里奥", "任天堂版权所有");
        ipDatabase.put("皮卡丘", "宝可梦公司版权所有");

        commercialIPs = new HashSet<>(Arrays.asList(
                "漫威角色", "DC角色", "热门动漫角色"
        ));
    }

    @Override
    protected boolean canHandle(ContentCheckRequest request) {
        // 处理所有类型内容
        return true;
    }

    @Override
    protected CheckResult doCheck(ContentCheckRequest request) {
        String content = request.getContentData().toString();

        // 检查IP侵权
        for (String ip : ipDatabase.keySet()) {
            if (content.contains(ip)) {
                applyWatermark(request);
                return new CheckResult(true, RiskLevel.MEDIUM,
                        "发现IP内容: " + ip + "，已添加水印", 0.92, "WATERMARK");
            }
        }

        // 检查商业IP
        for (String ip : commercialIPs) {
            if (content.contains(ip)) {
                return new CheckResult(false, RiskLevel.HIGH,
                        "发现商业IP侵权: " + ip, 0.88, "BLOCK");
            }
        }

        return new CheckResult(true, RiskLevel.LOW, "未发现版权问题", 0.95, "PASS");
    }

    public void applyWatermark(ContentCheckRequest request) {
        System.out.println("   添加版权水印: " + watermarkTemplate);
        request.getMetadata().put("watermark", watermarkTemplate);
    }

    public void addIPToDatabase(String ipName, String copyrightInfo) {
        ipDatabase.put(ipName, copyrightInfo);
    }
}
